package com.daxt.controller.filemanager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daxt.common.result.PageInfo;
import com.daxt.common.result.PageUtil;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.use.UseUserRecordLogMapper;
import com.daxt.model.service.use.vo.UseUserRecordLog;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "档案利用")
@RestController
@RequestMapping("/use")
public class UseController {
	
	@Autowired
	private UseUserRecordLogMapper useUserRecordLogMapper;
	
	@ApiOperation(value = "获取列表", notes = "")
	@GetMapping("/list")
	public Result<PageInfo<UseUserRecordLog>> list(@ApiParam("") @RequestParam(value = "pageNum", required = false) Integer pageNum,
			@ApiParam("") @RequestParam(value = "pageSize", required = false) Integer pageSize,
			@ApiParam("") @RequestParam(value = "type", required = false) Integer type,
			@ApiParam("鉴定开始时间") @RequestParam(value = "startTime", required = false)String startTime,
			@ApiParam("鉴定结束时间") @RequestParam(value = "endTime", required = false)String endTime,
			@ApiParam("题名") @RequestParam(value = "title", required = false)String title
			) {
		if (pageNum == null || pageSize == null) {
			pageNum = 1;
			pageSize = 10;
		}
		Page<UseUserRecordLog> page = new Page<UseUserRecordLog>(pageNum, pageSize);
		QueryWrapper<UseUserRecordLog> queryWrapper = new QueryWrapper<UseUserRecordLog>();
		if(!StringUtils.isEmpty(type)) {
		queryWrapper.eq("recordLogType", type);
		}
		if(!StringUtils.isEmpty(startTime)&&!StringUtils.isEmpty(endTime)) {
			queryWrapper.between("createTime", startTime, endTime);
		}
		if(!StringUtils.isEmpty(title)) {
			queryWrapper.eq("title", title);
			}
		IPage<UseUserRecordLog> info = useUserRecordLogMapper.selectPage(page, queryWrapper);
		
		PageInfo<UseUserRecordLog> data = PageUtil.data(info.getPages(), info.getCurrent(), info.getTotal(), info.getRecords());
		return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, data);
	}
}
